import { getSubCategoryAPI } from "@/apis/category";
import type { Category } from "@/types/category/category";
import { onMounted, ref } from "vue";
import { onBeforeRouteUpdate, useRoute } from "vue-router";
//获取面包屑导航数据
export function useSubCategory() {
  const subCategoryDate = ref<Category>({} as Category);
  const route = useRoute();
	const id = route.params.id;
  const getSubCategory = async (id = route.params.id) => {
    const res = await getSubCategoryAPI(id);
    subCategoryDate.value = res.data.result;
  };
  onMounted(() => {
    getSubCategory();
  });
  onBeforeRouteUpdate((to) => {
    getSubCategory(to.params.id);
  });
  return {
    subCategoryDate,
		id
  };
}
